package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogLanRuoSiEliminate1;
import com.yanqu.road.entity.log.LogLanRuoSiEliminate2;
import com.yanqu.road.entity.log.LogLanRuoSiEnergy;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogLanRuoSiDaoImpl extends TempDao {


    public boolean addLogLanRuoSiEliminate1List(List<LogLanRuoSiEliminate1> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_lanruosi_eliminate_1(userId,activityId,multi,bombList,count,score,monsterList,damageList,bloodList,roundWave,time) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLanRuoSiEliminate1 data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMulti()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBombList()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCount()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getScore()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getMonsterList()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getDamageList()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBloodList()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getRoundWave()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogLanRuoSiEliminate2List(List<LogLanRuoSiEliminate2> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_lanruosi_eliminate_2(userId,activityId,multi,maxCon,count,score,monsterList,damageList,bloodList,roundWave,time) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLanRuoSiEliminate2 data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMulti()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getMaxCon()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCount()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getScore()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getMonsterList()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getDamageList()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBloodList()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getRoundWave()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogLanRuoSiEnergyList(List<LogLanRuoSiEnergy> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_lanruosi_energy(userId,activityId,type,changeCount,newCount,time) VALUES(?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogLanRuoSiEnergy data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getChangeCount()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNewCount()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
